package com.tfswx.ruleengine.compute.gzjy.felfunc;

import com.greenpineyu.fel.context.FelContext;
import com.tfswx.ruleengine.compute.gzjy.BaseFn;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Ricky
 * @date 2021/4/15
 */
public class Length extends BaseFn {
    @Override
    public Object call(Object[] arguments, FelContext context) {
        String str = String.valueOf(arguments[0]);
        if (str == null) {
            return 0;
        }
        return str.length();
    }

    @Override
    public String getZwmc() {
        return "字符串长度";
    }

    @Override
    public boolean isExport() {
        return true;
    }

    @Override
    public boolean isBuiltIn() {
        return true;
    }

    @Override
    public List<Param> getParams() {
        List<Param> params = new ArrayList<>();
        params.add(new Param("str"));
        return params;
    }

    @Override
    public String getName() {
        return "length";
    }
}
